package com.dq.domain.record;

import com.dq.domain.base.BaseEntity;
import com.dq.domain.orders.UserOrder;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author luchangtong
 * @Date 2019/11/25 9:48
 */
@Data
@Entity
@ApiModel("收益记录（收益/返金）")
public class ProfitRecord extends BaseEntity {
    @ApiModelProperty("用户")
    @ManyToOne
    protected SysUser user;
    @ApiModelProperty("收益来源类型")
    @Enumerated(EnumType.ORDINAL)
    protected ChangeProfitType changeProfitType;
    @ApiModelProperty("收益变动类型")
    @Enumerated(EnumType.ORDINAL)
    protected ProfitChangeType profitChangeType;
    @ApiModelProperty("变动数量")
    protected BigDecimal changeNum;
    @ApiModelProperty("用户销售单")
    @ManyToOne
    protected UserOrder userOrder;

    public enum ChangeProfitType{
        extension("推广"),
        rakeBack("返佣"),
        consume("消费");
        public String name;
        ChangeProfitType(String name){
            this.name = name;
        }
    }

    public enum ProfitChangeType{
        add("加"),
        less("减"),;
        public String mean;
        ProfitChangeType(String mean){
            this.mean = mean;
        }
    }
    @Data
    @ApiModel("收益记录视图")
    public static class ProfitRecordVo{
        @ApiModelProperty("收益来源类型")
        protected String changeProfitType;
        @ApiModelProperty("收益变动类型")
        protected String profitChangeType;
        @ApiModelProperty("变动数量")
        protected BigDecimal changeNum;
        @ApiModelProperty("时间")
        protected String createTime;
    }

    public ProfitRecordVo toProfitRecordVo(){
        ProfitRecordVo vo = new ProfitRecordVo();
        vo.changeProfitType = this.changeProfitType.name;
        vo.profitChangeType = this.profitChangeType.mean;
        vo.changeNum = this.changeNum;
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        return vo;
    }

    @Data
    @ApiModel("收益记录视图")
    public static class ProfitRecordList{
        protected List<ProfitRecordVo> profitRecordVos;
        protected Long totalNum;
        @ApiModelProperty("累计收益")
        protected BigDecimal accumulatedIncome;
        @ApiModelProperty("可消费收益")
        protected BigDecimal mayProfit;
        @ApiModelProperty("消费返金")
        protected BigDecimal profitReturn;
    }

    public ProfitRecordList toProfitRecordList(List<ProfitRecordVo> profitRecordVos ,Long totalNum,BigDecimal accumulatedIncome,BigDecimal mayProfit,BigDecimal profitReturn){
        ProfitRecordList vo = new ProfitRecordList();
        vo.profitRecordVos =profitRecordVos;
        vo.totalNum = totalNum;
        vo.accumulatedIncome = accumulatedIncome;
        vo.mayProfit = mayProfit;
        vo.profitReturn = profitReturn;
        return vo;
    }
}
